package com.inspur.edp.bff.core.changeset;

import com.inspur.edp.cef.api.session.ICefSession;
import com.inspur.edp.cef.core.changesetmgr.ChangesetManager;
import com.inspur.edp.cef.entity.changeset.IChangeDetail;

import java.util.HashMap;
import java.util.Map;

public class BffChangeManager extends ChangesetManager {
    public BffChangeManager(ICefSession session, String entityType) {
        super(entityType, session);
    }

    public void appendCurrentTemplateChange(IChangeDetail change) {
        appendChange(change.getDataID(), 1, change);
        acceptChange(change.getDataID(), 1);
    }

    public IChangeDetail getCurrentChange(String dataId) {
        return getChange(dataId, 0);
    }

    public Map<String, IChangeDetail> getCurrentChange() {
        Map<String, Map<Integer, IChangeDetail>> changes = getChanges();
        Map<String, IChangeDetail> tempChanges = new HashMap<>();
        if (changes == null || changes.size() == 0)
            return tempChanges;
        for (Map.Entry<String, Map<Integer, IChangeDetail>> mapEntry : changes.entrySet()) {
            String dataId = mapEntry.getKey();
            IChangeDetail changeDetail = mapEntry.getValue() == null ? null : mapEntry.getValue().get(0);
            tempChanges.put(dataId, changeDetail);
        }
        return tempChanges;
    }
}
